package com.dengdingqi.dd.comfig;

import com.dengdingqi.dd.mapper.EbProductCategoryMapper;
import com.dengdingqi.dd.model.EbProductCategory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import java.util.List;

@Component
public class InitContext implements CommandLineRunner {
    @Resource
    private EbProductCategoryMapper ebProductCategoryMapper;
    @Resource
    private ServletContext application;
    @Override
    public void run(String... argd) throws Exception{
        System.out.println("======spring boot 项目初始化");
        //查询大小类
        List<EbProductCategory> bigs=ebProductCategoryMapper.selectBigCategory();
        List<EbProductCategory> smalls=ebProductCategoryMapper.selectSmallCategory();
        //放到全局的context域中
        application.setAttribute("bigs",bigs);
        application.setAttribute("smalls",smalls);

    }

}
